package com.example.yls.myapplication;

import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    private SQLiteDatabase db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                createDataBase();
            }

        });
        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                createStudentTable();
            }
        });
    }

    private void createStudentTable() {
        String sql="create table student (stuno int,name varchar(20),age int)";
        db.execSQL(sql);
    }

    private void createDataBase() {
        String path=getFilesDir().getAbsolutePath()+ File.separator+"stu.db";
        Log.e("MainActivity","path="+path);
        db= SQLiteDatabase.openOrCreateDatabase(path,null);
    }
}
